#include "TcpServer.hpp"
#include "Http.hpp"
#include <memory>

void Usage(string local)
{
    cerr << "Usage:" << local << "port" << endl;
}

HttpResponse Login(HttpRequest &req)
{
    LOG(LogLevel::DEBUG) << "-----Login: " << req.Body();
}

HttpResponse Register(HttpRequest &req)
{
    LOG(LogLevel::DEBUG) << "-----Register" << req.Body();
}

HttpResponse Search(HttpRequest &req)
{
    LOG(LogLevel::DEBUG) << "-----Search" << req.Body();
}

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    EnableConsoleLogStrategy();

    unique_ptr<Http> http = make_unique<Http>();

    http->Register("./login", Login);
    http->Register("./search", Search);
    http->Register("./register", Register);

    uint16_t port = stoi(argv[1]);
    unique_ptr<TcpServer> tsvr = make_unique<TcpServer>(port, [&http](string &req)
                                { return http->RespStr(req); });

    tsvr->Run();

    return 0;
}